//  新增用药方案
//  TabletPlanViewController.m
//  yilutongxing
//
//  Created by ios-21 on 17/4/16.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "TabletPlanViewController.h"
#import "TabletNameTableViewController.h"
#import <QMUIKit/QMUIKit.h>
#import "CommonDefine.h"
#import "DataUtils.h"
#import "TimeTools.h"
#import "IQActionSheetPickerView.h"
#import "RPMedicineSinglePlan.h"
#import "SinglelineTextFormViewController.h"
#import "TabletPlanTimesAndDosesCell.h"

#define TIMEDOSE_CELL @"timedose_cell"

#define MAX_TAKETIMES 10 //每种药每天服药次数最大值
#define MAX_MEDICINENUM 1000 //每个方案的药品数量最大值
#define MAX_PLANNUM 10000 //用药方案数量最大值

#define URL_AddOrModifyPlan @"/api/sick-medicine-plans"

@interface TabletPlanViewController ()<UITableViewDelegate,UITableViewDataSource,IQActionSheetPickerViewDelegate,
                                        TabletNameViewDelegate, SinglelineTextFormViewControllerDelegate,
                                        UITextFieldDelegate, NetworkUtilsDelegate, TabletPlanTimesAndDosesDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tabletPlanTableView;
@property (nonatomic, strong) QMUIFillButton *m_btn_next;

@property(nonatomic,strong)NSArray *countArr;
@property(nonatomic,strong)NSDictionary *countDic;
@property(nonatomic,strong)NSArray *countNameArr;
@property(nonatomic,strong)NSArray *hourArr;
@property(nonatomic,strong)NSArray *secondArr;
@property(nonatomic,strong)NSArray *unitArr;
@property(nonatomic,strong) UITextField *tf;
@property(nonatomic,strong)NSMutableDictionary *pickerDic;//缓存所有选择器对象
@end

@implementation TabletPlanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.tabletPlanTableView.delegate = self;
    self.tabletPlanTableView.dataSource = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackGroundImage"] forBarMetrics:UIBarMetricsDefault];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(saveAction)];
    UIImage *img = [[UIImage imageNamed:@"返回"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:img style:UIBarButtonItemStyleDone target:self action:@selector(backAction)];
    
    [self.tabletPlanTableView registerNib:[UINib nibWithNibName:@"TabletPlanTimesAndDosesCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:TIMEDOSE_CELL];
    
    //准备数据
    if (self.isAdd) {
        if (!_plan) {
            self.plan = [RPMedicinePlan new];
            RPMedicineSinglePlan *single = [RPMedicineSinglePlan new];
            single.frequency = @"每天一次";
            single.timesArr = [NSMutableArray arrayWithObjects:@"", nil];
            single.doseArr = [NSMutableArray arrayWithObjects:@"", nil];
            single.unitArr = [NSMutableArray arrayWithObjects:@"ml", nil];
            _plan.medicines = [NSMutableArray arrayWithObjects:single, nil];
        }
        else {
            self.plan = [self.plan copy];
        }
        
        self.plan.startTime = [TimeTools getCurrentTimeYMD];
        self.plan.endTime = @"";
    }
    else {
        for (int i=0; i<_plan.medicines.count; i++) {
            RPMedicineSinglePlan *single = _plan.medicines[i];
            if (!single.timesArr || single.timesArr.count==0) {
                NSMutableArray *tmpArr = [[single.times componentsSeparatedByString:@","] mutableCopy];
                if ([((NSString*)tmpArr.lastObject) isEqualToString:@""]) {
                    [tmpArr removeLastObject];
                }
                single.timesArr = tmpArr;
            }
            if (!single.doseArr || single.doseArr.count==0) {
                NSMutableArray *tmpArr = [[single.dose componentsSeparatedByString:@","] mutableCopy];
                if ([((NSString*)tmpArr.lastObject) isEqualToString:@""]) {
                    [tmpArr removeLastObject];
                }
                single.doseArr = tmpArr;
            }
            if (!single.unitArr || single.unitArr.count==0) {
                NSMutableArray *tmpArr = [[single.unit componentsSeparatedByString:@","] mutableCopy];
                if ([((NSString*)tmpArr.lastObject) isEqualToString:@""]) {
                    [tmpArr removeLastObject];
                }
                single.unitArr = tmpArr;
            }
        }
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.title = self.__title;
    [self.tabletPlanTableView reloadData];
}
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    self.title = @" ";

}

#pragma mark - tableview datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _plan.medicines.count+2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSInteger n = 0;
    if (section==0) {
        n = 2;
    }
    else if(section==(_plan.medicines.count+1)){
        n = 1;
    }
    else {
        RPMedicineSinglePlan *singleplan = _plan.medicines[section-1];
        n = 2+singleplan.timesArr.count;
    }
    return n;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section>0
        //&& indexPath.section<_plan.medicines.count+1
        && indexPath.row>1) {
        return 66;
    }
    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc]init];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section>0 && _plan.medicines.count>1 && section<_plan.medicines.count+1) {
        return 30;
    }
    if (section==(_plan.medicines.count+1)) {
        return FOOTER_HEIGHT;
    }
    else
        return 0.01;
}
//footer里构造添加按钮
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section>0 && _plan.medicines.count>1 && section<_plan.medicines.count+1) {
        UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.width, 30)];
        [header setBackgroundColor:COLOR(235, 235, 241)];
        UIButton *deletebtn = [[UIButton alloc]initWithFrame:CGRectMake(tableView.width - 70, 5, 60, 20)];
        deletebtn.tag = section;
        [deletebtn setTitle:@"删除" forState:UIControlStateNormal];
        [deletebtn setTitleColor:Bluecolor forState:UIControlStateNormal];
        [deletebtn addTarget:self
                      action:@selector(deleteMedicineBtnClick:)
            forControlEvents:UIControlEventTouchUpInside];
        [header addSubview:deletebtn];
        return header;
    }
    else if (section==(_plan.medicines.count+1)) {
        UIView *rowview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, FOOTER_HEIGHT)];
        _m_btn_next = [[QMUIFillButton alloc] initWithFillType:QMUIFillButtonColorBlue];
        [self.m_btn_next setTitle:@"添加" forState:UIControlStateNormal];
        [self.m_btn_next setFrame:CGRectMake(20, (FOOTER_HEIGHT-50)/2,SCREEN_WIDTH-40,50)];
        [self.m_btn_next addTarget:self action:@selector(onAddClick) forControlEvents:UIControlEventTouchUpInside];
        [rowview addSubview:self.m_btn_next];
        return rowview;
    }
    return [[UIView alloc]init];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    // 定义cell标识  每个cell对应一个自己的标识
    NSString *CellIdentifier = [NSString stringWithFormat:@"cell%ld%ld", (long)indexPath.section, (long)indexPath.row];
    // 通过不同标识创建cell实例
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    // 判断为空进行初始化  --（当拉动页面显示超过主页面内容的时候就会重用之前的cell，而不会再次初始化）
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    if (indexPath.section==0) {
        cell.accessoryType = UITableViewCellAccessoryNone;
        if (indexPath.row==0) {
            cell.textLabel.text = @"开始日期";
            cell.detailTextLabel.text = _plan.startTime;
        }
        else{
            cell.textLabel.text = @"结束日期";
            cell.detailTextLabel.text = _plan.endTime;
        }
        
    }
    else if (indexPath.section==(_plan.medicines.count+1)){
        cell.textLabel.text = @"备注";
        cell.detailTextLabel.text = _plan.desc;
    }
    else {
        RPMedicineSinglePlan *singleplan = _plan.medicines[indexPath.section-1];
        if (indexPath.row==0){
            cell.textLabel.text = @"药物名称";
            cell.detailTextLabel.text = singleplan.medicine.name;
        }
        else if (indexPath.row==1){
            cell.textLabel.text = @"服用次数";
            cell.detailTextLabel.text = singleplan.frequency;
        }
        else {//if (indexPath.row>1 && (indexPath.row-2)<=(((NSInteger)singleplan.timesArr.count)-1)){
            TabletPlanTimesAndDosesCell *cell_t = [tableView dequeueReusableCellWithIdentifier:TIMEDOSE_CELL];
            if (!cell_t) {
                cell_t = [tableView dequeueReusableCellWithIdentifier:TIMEDOSE_CELL forIndexPath:indexPath];
            }
            cell_t.tag = ROWINDEX(indexPath);
            cell_t.delegate = self;
            [cell_t setOrdertitle:indexPath.row-1];
            [cell_t setTaketime:singleplan.timesArr[indexPath.row-2]];
            [cell_t setDose:singleplan.doseArr[indexPath.row-2]];
            [cell_t setUnit:singleplan.unitArr[indexPath.row-2]];
            
            cell = cell_t;
        }
    }
    
    return cell;
}
//点击响应
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger index = ROWINDEX(indexPath);
    NSNumber *dicKey = [NSNumber numberWithInteger:index];
    if (indexPath.section==0) { //用药日期
        /*
        if (self.plan.id==0) { //新增
            IQActionSheetPickerView *picker = [[IQActionSheetPickerView alloc] initWithTitle:@"" delegate:self];
            [picker setTag:index];
            [self.pickerDic setObject:@1 forKey:dicKey];
            [picker setActionSheetPickerStyle:IQActionSheetPickerStyleDatePicker];
            [picker show];
        }
        */
    }
    else if (indexPath.section==(_plan.medicines.count+1)){//备注
        SinglelineTextFormViewController *inputView = [SinglelineTextFormViewController new];
        inputView.delegate = self;
        inputView.indexPath = indexPath;
        inputView.title = @"输入备注";
        [self.navigationController pushViewController:inputView animated:YES];
    }
    else { //用药方案
        RPMedicineSinglePlan *singleplan = self.plan.medicines[indexPath.section-1];
        if (indexPath.row==0){//药品名称
            TabletNameTableViewController *tnTVC = [TabletNameTableViewController new];
            tnTVC.index = indexPath.section-1;
            tnTVC.delegate = self;
            [self.navigationController pushViewController:tnTVC animated:YES];
        }
        else if(indexPath.row==1) { //用药频率
            IQActionSheetPickerView *picker = [[IQActionSheetPickerView alloc] initWithTitle:@"" delegate:self];
            picker.titleFont = [UIFont systemFontOfSize:12];
            picker.titleColor = [UIColor redColor];
            [picker setTag:index];
            [self.pickerDic setObject:@2 forKey:dicKey];
            [picker setTitlesForComponents:@[self.countArr]];
            [picker show];
        }
        else if(indexPath.row>1 && (indexPath.row-2)<=(((NSInteger)singleplan.timesArr.count)-1)){ //第n次用药时间
            
        }
        else { //剂量（单位）
            
        }
    }
}

#pragma mark - ActionSheetPickerViewDelegate
-(void)actionSheetPickerView:(IQActionSheetPickerView *)pickerView didSelectDate:(NSDate *)date
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    NSNumber *pickerIndex = [self.pickerDic objectForKey:[NSNumber numberWithInteger:pickerView.tag]];
    switch ([pickerIndex unsignedIntegerValue])
    {
        case 1: //用药日期
            {
                [formatter setDateStyle:NSDateFormatterMediumStyle];
                [formatter setTimeStyle:NSDateFormatterNoStyle];
                [formatter setDateFormat:@"yyyy-MM-dd"];
                _plan.startTime = [formatter stringFromDate:date];
            }
            break;
        case 3: //用药时间
            {
                [formatter setDateStyle:NSDateFormatterNoStyle];
                [formatter setTimeStyle:NSDateFormatterMediumStyle];
                [formatter setDateFormat:@"HH:mm"];
                NSIndexPath *ip = DEROWINDEX(pickerView.tag);
                NSInteger timesIndex = ip.section-1;
                RPMedicineSinglePlan *singleplan = self.plan.medicines[timesIndex];
                singleplan.timesArr[ip.row-2] = [formatter stringFromDate:date];
                self.plan.medicines[timesIndex] = singleplan;
            }
            break;
    }
    [self.tabletPlanTableView reloadData];
}
-(void)actionSheetPickerView:(IQActionSheetPickerView *)pickerView didSelectTitles:(NSArray *)titles
{
    NSIndexPath *ip = DEROWINDEX(pickerView.tag);
    NSInteger dataIndex = ip.section-1;
    RPMedicineSinglePlan *singleplan = _plan.medicines[dataIndex];
    NSString *valStr = [titles componentsJoinedByString:@""];
    NSNumber *pickerIndex = [self.pickerDic objectForKey:[NSNumber numberWithInteger:pickerView.tag]];
    switch ([pickerIndex unsignedIntegerValue])
    {
        case 2: //用药次数
        {
            int count = [[self.countDic objectForKey:valStr] intValue];
            
            [singleplan.timesArr removeAllObjects];
            [singleplan.doseArr removeAllObjects];
            [singleplan.unitArr removeAllObjects];
            singleplan.frequency = valStr;
            for (int i=0; i<count; i++) {
                [singleplan.timesArr addObject:@""];
                [singleplan.doseArr addObject:@""];
                [singleplan.unitArr addObject:@"ml"];
            }
        }
            break;
        case 4:  //剂量单位
        {
            singleplan.unitArr[ip.row-2] = valStr;
        }
            break;
    }
    self.plan.medicines[dataIndex] = singleplan;
    [self.tabletPlanTableView reloadData];
}

#pragma mark - 事件响应
- (void)deleteMedicineBtnClick:(UIButton*)sender{
    debugLog(@"[SHENMI]deleteMedicineBtnClick %ld", sender.tag);
    if (self.plan.medicines.count<=1) {
        return;
    }
    
    NSUInteger i = sender.tag - 1;
    [self.plan.medicines removeObjectAtIndex:i];
    [self.tabletPlanTableView reloadData];
}

-(void)onAddClick{
    if (_plan.medicines.count>=MAX_MEDICINENUM) {
        return;
    }
    RPMedicineSinglePlan *singleplan = [RPMedicineSinglePlan new];
    singleplan.timesArr = [NSMutableArray arrayWithObjects:@"", nil];
    singleplan.doseArr = [NSMutableArray arrayWithObjects:@"", nil];
    singleplan.unitArr = [NSMutableArray arrayWithObjects:@"ml", nil];
    singleplan.frequency = @"";
    MedicinesModel *medicine = [MedicinesModel new];
    medicine.name = @"";
    singleplan.medicine = medicine;
    [_plan.medicines addObject:singleplan];
    
    [self.tabletPlanTableView reloadData];
}

-(void)saveAction{
    NSLog(@"保存");
    for (int i=0; i<self.plan.medicines.count; i++) {
        RPMedicineSinglePlan *singleplan = self.plan.medicines[i];
        singleplan.times = [singleplan.timesArr componentsJoinedByString:@","];
        singleplan.timesArr = nil;
        singleplan.dose = [singleplan.doseArr componentsJoinedByString:@","];
        singleplan.doseArr = nil;
        singleplan.unit = [singleplan.unitArr componentsJoinedByString:@","];
        singleplan.unitArr = nil;
        self.plan.medicines[i] = singleplan;
    }
    
    if (self.plan.id==0 || self.isAdd) {  //是新增的
        //self.plan.userId = [[DataUtils getMyUID] stringValue];
        for (int i=0; i<self.plan.medicines.count; i++) {
            RPMedicineSinglePlan *sp = self.plan.medicines[i];
            sp.id = 0;
            sp.timesArr = nil;
        }
        NSMutableDictionary *planDic = [self.plan mj_keyValuesAdd];
        [planDic removeObjectForKey:@"id"];
        if (!_isOnlyLocal) {
            [[YZENetwork sharedInstace]postRequestWithUrl:[BASE stringByAppendingString:URL_AddOrModifyPlan]
                                               parameters:planDic
                                                 delegate:self
                                               requestTag:1
                                             successBlock:^(id responseObject)
            {
                [QMUITips hideAllToastInView:self.view animated:YES];
                [self backAction];
            }];
            [QMUITips showLoadingInView:self.view];
        }
        if ([self.delegate respondsToSelector:@selector(addPlanFor:)]) {
            [self.delegate addPlanFor:self.plan];
        }
        if (_isOnlyLocal) {
            [self backAction];
        }
    }
    else if (self.plan.id>0){  //是修改已有数据
        NSMutableDictionary *planDic = [self.plan mj_keyValuesAdd];
        [planDic removeObjectForKey:@"userId"];
        
        if (!_isOnlyLocal) {
            [[YZENetwork sharedInstace]putRequestWithUrl:[BASE stringByAppendingString:URL_AddOrModifyPlan]
                                              parameters:planDic
                                                delegate:self
                                              requestTag:2
                                            successBlock:^(id responseObject)
             {
                 [QMUITips hideAllToastInView:self.view animated:YES];
                 [self backAction];
             }];
            [QMUITips showLoadingInView:self.view];
        }
        if ([self.delegate respondsToSelector:@selector(updatePlanFor:index:)]) {
            [self.delegate updatePlanFor:self.plan index:self.index];
        }
        if (_isOnlyLocal) {
            [self backAction];
        }
    }
}

-(void)backAction{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - TabletNameViewDelegate
-(void)backMedicineName:(MedicinesModel *)model index:(long)index{
    RPMedicineSinglePlan *singleplan =  self.plan.medicines[index];
    singleplan.medicine = model;
    singleplan.medicineName = model.name;
}

#pragma mark - SinglelineTextFormViewControllerDelegate
-(void)backData:(NSString *)content identifier:(NSIndexPath *)indexPath{
    self.plan.desc = content;
    UITableViewCell *cell = [self.tabletPlanTableView cellForRowAtIndexPath:indexPath];
    cell.detailTextLabel.text = content;
}

#pragma mark 剂量输入响应
- (void)doseTextFieldChanged:(UITextField *)textField{
    if (textField.text.length==0) {
        return;
    }
    RPMedicineSinglePlan *singlePlan = self.plan.medicines[textField.tag];
    singlePlan.dose = textField.text;
}

#pragma mark - TabletPlanTimesAndDosesDelegate
- (void)onTimerowTapedFortag:(NSInteger)tag{
    IQActionSheetPickerView *picker = [[IQActionSheetPickerView alloc] initWithTitle:@"" delegate:self];
    [picker setTag:tag];
    [self.pickerDic setObject:@3 forKey:[NSNumber numberWithInteger:tag]];
    [picker setActionSheetPickerStyle:IQActionSheetPickerStyleTimePicker];
    [picker show];
}

- (void)onDoserowTapedFortag:(NSInteger)tag{
    IQActionSheetPickerView *picker = [[IQActionSheetPickerView alloc] initWithTitle:@"" delegate:self];
    picker.titleFont = [UIFont systemFontOfSize:12];
    picker.titleColor = [UIColor redColor];
    [picker setTag:tag];
    [self.pickerDic setObject:@4 forKey:[NSNumber numberWithInteger:tag]];
    [picker setTitlesForComponents:@[self.unitArr]];
    [picker show];
}

- (void)onDosetexted:(NSString *)text forTag:(NSInteger)tag{
    NSIndexPath *indexPath = DEROWINDEX(tag);
    RPMedicineSinglePlan *singlePlan = self.plan.medicines[indexPath.section-1];
    singlePlan.doseArr[indexPath.row-2] = text;
}

#pragma mark - 配置数据
-(NSString*)__title{
    if (!___title) {
        ___title = @"新增方案";
    }
    return ___title;
}

-(NSArray *)countArr{
    if (!_countArr) {
        _countArr=@[@"每天一次",@"每天两次",@"每天三次",@"每天四次"];
    }
    return _countArr;
}
-(NSArray *)countNameArr{
    if (!_countNameArr) {
        _countNameArr = @[@"第一次",@"第二次",@"第三次",@"第四次"];
    }
    return _countNameArr;
}
-(NSDictionary*)countDic{
    if (!_countDic) {
        _countDic = @{@"每天一次":@1,@"每天两次":@2,@"每天三次":@3,@"每天四次":@4};
    }
    return _countDic;
}
-(NSArray *)hourArr{
    if (!_hourArr) {
        _hourArr=@[@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24"];
    }
    return _hourArr;
}
-(NSArray *)secondArr{
    if (!_secondArr) {
        _secondArr=@[@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",@"57",@"58",@"59"];
    }
    return _secondArr;
}

-(NSArray *)unitArr{
    if (!_unitArr) {
        _unitArr=@[@"粒",@"片",@"丸",@"ml",@"mg",@"g"];
    }
    return _unitArr;
}
- (NSMutableDictionary *)pickerDic{
    if (!_pickerDic) {
        _pickerDic = [NSMutableDictionary dictionary];
    }
    return _pickerDic;
}
#pragma mark - 辅助函数
- (UITextField *)createUITextField:(NSUInteger)tag{
    UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(200,8, 60, 28)];
    tf.tag = tag;
    tf.backgroundColor= COLOR(250, 250, 250);
    tf.layer.masksToBounds=YES;
    tf.layer.cornerRadius=tf.frame.size.height/2;
    tf.layer.borderWidth=1;
    tf.layer.borderColor=COLOR_ALPHA(240, 240, 240, 1.0).CGColor;
    tf.textAlignment=NSTextAlignmentCenter;
    [tf addTarget:self action:@selector(doseTextFieldChanged:) forControlEvents:UIControlEventEditingChanged];
    return tf;
}

#pragma mark - 网络代理
- (void)OnStartWithRequestTag:(int)tag{}
- (void)OnFinishWithRequestTag:(int)tag{}
- (void)OnSuccess:(id)responseObject requestTag:(int)tag{}
- (void)OnFail:(NSString *)errorMsg errorCode:(NSInteger)errorCode requestTag:(int)tag{
    [QMUITips hideAllToastInView:self.view animated:YES];
    [QMUITips showError:@"上传数据失败！" inView:self.view hideAfterDelay:2];
}

@end
